//
//  CYPreviewToolTip.m
//  T-BoxManager
//  
//  Created by 车音 on 2019/6/24.
//  Copyright © 2019 CheYin. All rights reserved.
//

#import "CYPreviewToolTip.h"
#import "CYWToast.h"
#import "NICustomLoading.h"

@interface CYPreviewToolTip ()

@property(nonatomic, strong ) UIView *loadingCfgView;
@property(nonatomic, strong ) UIView *loadingView;
//@property(nonatomic, strong ) NSMutableArray *loadingSoure;
@property(nonatomic, strong ) MBProgressHUD *progressHUD;
@end

@implementation CYPreviewToolTip

+ (instancetype)initInstance {
    static CYPreviewToolTip *_instance;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _instance = [[[self class] alloc] init];
    });
    return _instance;
}


#pragma mark - ProgressHUD
- (MBProgressHUD *)progressHUD {
    if (_progressHUD) {
        return _progressHUD;
    }
    UIView *rootView = [UIApplication sharedApplication].keyWindow.rootViewController.view;
    _progressHUD = [[MBProgressHUD alloc] initWithView:rootView];
//    _progressHUD.
//    [rootView addSubview:self.progressHUD];
    return _progressHUD;
}

- (void)showHudLoading {
    [[NICustomLoading initInstance] show];
    
    dispatch_time_t delayTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(30.0 * NSEC_PER_SEC));
    dispatch_after(delayTime, dispatch_get_main_queue(), ^{
        [self hideHudLoading];
    });

//    [MBProgressHUD showHUDAddedTo:[UIApplication sharedApplication].keyWindow.rootViewController.view animated:YES];

//    [[self progressHUD] showAnimated:YES];
}

- (void)hideHudLoading {
    [[NICustomLoading initInstance] hide];

//    [MBProgressHUD showHUDAddedTo:[UIApplication sharedApplication].keyWindow.rootViewController.view animated:YES];

//    [[self progressHUD] hideAnimated:NO];
    
}


#pragma mark -  General Toast View

- (void)showToast:(NSString *)text {
    if ([text isKindOfClass:[NSString class]]) {
        if (text.length > 0) {
            [self showToast:text type:DDPToastTypePrompt];
        }
    }
}

- (void)showSuccessToast:(NSString *)text {
    [self showToast:text type:DDPToastTypeSuccess];
}

- (void)showFailureToast:(NSString *)text {
    [self showToast:text type:DDPToastTypeError];
}

- (void)showToast:(NSString *)text type:(DDPToastType)type {
    switch (type) {
        case DDPToastTypeSuccess:
            [CYWToast ddpShowWithImage:[UIImage imageNamed:@"success"] text:text duration:1];
            break;
        case DDPToastTypeError:
            [CYWToast ddpShowWithImage:[UIImage imageNamed:@"error"] text:text duration:1];
            break;
        default:
            [CYWToast ddpShowWithImage:[UIImage imageNamed:@"prompt"] text:text duration:1];
            break;
    }
}


@end

